/**
 * <p>Copyright: Copyright (c) 2014</p>
 * <p>Company: ---Technology Co. Ltd</p>
 * <p>2014-4-30</p>
 * @author Jan.Zhang
 */
package com.xianl.busiplat.common;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AbstractRefreshableWebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;



/** 
 * desc:
 * <p>author: Jan.Zhang </p>
 * date: 2014-4-30
 */
public class PlatWebListener extends ContextLoaderListener implements ServletContextListener {

	/* 
	 * desc:
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent event) {
		super.contextDestroyed(event);
		ServletContext context = event.getServletContext();
		WebApplicationContext webApplicationContext =WebApplicationContextUtils.getRequiredWebApplicationContext(context);
		((AbstractRefreshableWebApplicationContext)webApplicationContext).close();
		
	}

	/* 
	 * desc:
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
//		ServletContext context = event.getServletContext();
//		String appPath = context.getRealPath("");
//		String cfgFilePath=context.getInitParameter("cfgFilePath");
//		if(null==cfgFilePath){
//			cfgFilePath =appPath+"/WEB-INF/classes/config/platConfig.properties";
//		}
//		CommonConfig.loadConfig(cfgFilePath);
		
	}
}
